-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add app engine credentials #46
Conversation
from google.auth import credentials | ||
from google.auth import exceptions | ||
|
||
|
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
not available. | ||
""" | ||
# pylint: disable=unused-argument | ||
if not app_identity: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Returns: | ||
bool: True if there are no scopes set otherwise False. | ||
""" | ||
return True if not self._scopes else False |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Raises: | ||
EnvironmentError: If the App Engine APIs are unavailable. | ||
""" | ||
if not app_identity: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
credentials.Credentials): | ||
"""App Engine standard environment credentials. | ||
|
||
These credentials use the App Engine App Idenity API to obtain access |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
try: | ||
from google.appengine.api import app_identity | ||
except ImportError: | ||
app_identity = None |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
service_account_id (str): The service account ID passed into | ||
:func:`google.appengine.api.app_identity.get_access_token`. | ||
This is not required as the default application service account | ||
ID will be used. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
google.auth.exceptions.RefreshError: If the App Engine APIs are | ||
not available. | ||
""" | ||
# pylint: disable=unused-argument |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
@property | ||
def requires_scopes(self): | ||
"""Checks if the credentials requires scopes. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@pytest.fixture | ||
def app_engine(app_identity_mock): | ||
from google.auth import app_engine | ||
reload_module(app_engine) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
def app_engine(app_identity_mock): | ||
from google.auth import app_engine | ||
reload_module(app_engine) | ||
yield app_engine |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@pytest.fixture | ||
def app_engine_no_apis(): | ||
from google.auth import app_engine | ||
reload_module(app_engine) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
|
||
class TestCredentials(object): | ||
def test_default_state(self, app_engine): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
def test_refresh(self, now_mock, app_engine, app_identity_mock): | ||
token = 'token' | ||
ttl = 100 | ||
app_identity_mock.get_access_token.return_value = (token, ttl) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
self._service_account_id = service_account_id | ||
|
||
def refresh(self, request): | ||
"""Refresh the access token and scopes. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
"""Refresh the access token and scopes. | ||
|
||
Args: | ||
request (google.auth.transport.Request): Unused. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
scopes=scopes, service_account_id=self._service_account_id) | ||
|
||
def sign_bytes(self, message): | ||
"""Signs the given message. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@dhermes @nathanielmanistaatgoogle PTAL, should be good to go. |
LGTM |
Closes #36